home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.0 / stk-3 / blt-for-STk-3.0 / blt-1.9 / demos / barchart3 < prev    next >
Encoding:
Text File  |  1995-07-01  |  4.2 KB  |  134 lines

  1. #!../blt_wish -f
  2.  
  3. if [file exists ../library] {
  4.     set blt_library ../library
  5. }
  6. set graph .graph
  7.  
  8. blt_bitmap define pattern1 { {4 4} {01 02 04 08} }
  9. blt_bitmap define pattern2 { {4 4} {08 04 02 01} }
  10. blt_bitmap define pattern3 { {2 2} {01 02 } }
  11. blt_bitmap define pattern4 { {4 4} {0f 00 00 00} }
  12. blt_bitmap define pattern5 { {4 4} {01 01 01 01} }
  13. blt_bitmap define pattern6 { {2 2} {01 00 } }
  14. blt_bitmap define pattern7 { {4 4} {0f 01 01 01} }
  15. blt_bitmap define pattern8 { {8 8} {ff 00 ff 00 ff 00 ff 00 } }
  16. blt_bitmap define pattern9 { {4 4} {03 03 0c 0c} }
  17. blt_bitmap define hobbes { {25 25} {
  18.    00 00 00 00 00 00 00 00 00 c0 03 00 78 e0 07 00 fc f8 07 00 cc 07 04 00
  19.    0c f0 0b 00 7c 1c 06 00 38 00 00 00 e0 03 10 00 e0 41 11 00 20 40 11 00
  20.    e0 07 10 00 e0 c1 17 00 10 e0 2f 00 20 e0 6f 00 18 e0 2f 00 20 c6 67 00
  21.    18 84 2b 00 20 08 64 00 70 f0 13 00 80 01 08 00 00 fe 07 00 00 00 00 00
  22.    00 00 00 00 }
  23. }
  24.  
  25. option add *Blt_htext.font *Times-Bold-R*14*
  26. option add *graph.xTitle "X Axis Label"
  27. option add *graph.yTitle "Y Axis Label"
  28. option add *graph.title "A Simple Barchart"
  29. option add *graph.xFont *Times-Medium-R*12*
  30. option add *graph.elemBackground white
  31. option add *graph.elemRelief raised
  32.  
  33. set visual [winfo screenvisual .] 
  34. if { $visual != "staticgray" && $visual != "grayscale" } {
  35.     option add *print.background yellow
  36.     option add *quit.background red
  37. }
  38.  
  39. blt_htext .header -text \
  40. {This is an example of the blt_barchart widget.  The barchart has 
  41. many components; x and y axis, legend, crosshairs, elements, etc.  
  42. You can configure any component by pressing this %% 
  43. button $blt_htext(widget).config -text button \
  44.     -command "exec [list ../blt_wish -f ./grconf.tcl [winfo name .] $graph &]"\
  45.     -bg green
  46. $blt_htext(widget) append $blt_htext(widget).config
  47. %%.
  48.  
  49. To create a postscript file "bar.ps", press the %%
  50. button $blt_htext(widget).print -text {Print} -command {
  51.   $graph postscript bar.ps -pagewidth 6.5i -pageheight 9i -landscape true
  52. $blt_htext(widget) append $blt_htext(widget).print
  53. %% button.}
  54.  
  55. blt_barchart $graph -invert true 
  56. $graph xaxis configure -command FormatLabel -descending true
  57. $graph legend configure -mapped false
  58.  
  59. blt_htext .footer -text {Hit the %%
  60. button $blt_htext(widget).quit -text quit -command {destroy .} 
  61. $blt_htext(widget) append $blt_htext(widget).quit 
  62. %% button when you've seen enough.%%
  63. label $blt_htext(widget).logo -bitmap BLT
  64. $blt_htext(widget) append $blt_htext(widget).logo -padx 20
  65. %%}
  66.  
  67. set names { One Two Three Four Five Six Seven Eight }
  68. if { $visual == "staticgray" || $visual == "grayscale" } {
  69.     set fgcolors { white white white white white white white white }
  70.     set bgcolors { black black black black black black black black }
  71. } else {
  72.     set fgcolors { red green blue purple orange brown cyan navy }
  73.     set bgcolors { green blue purple orange brown cyan navy red }
  74. }
  75. set numColors [llength $names]
  76.  
  77. for { set i 0} { $i < $numColors } { incr i } {
  78.     $graph element create [lindex $names $i] \
  79.     -data { $i+1 $i+1 } \
  80.     -fg [lindex $fgcolors $i] \
  81.     -bg [lindex $bgcolors $i] \
  82.     -stipple pattern[expr $i+1]  \
  83.     -relief raised \
  84.     -bd 2 
  85. }
  86.  
  87. $graph element create Nine \
  88.     -ydata { -1.0 -2.0 -3.0 } \
  89.     -xdata { 9 } \
  90.     -fg red  \
  91.     -relief sunken -stacked true
  92. $graph element create Ten \
  93.     -data { 10 2 } \
  94.     -fg seagreen \
  95.     -stipple hobbes \
  96.     -background palegreen 
  97. $graph element create Eleven \
  98.     -data { 11 3.3 } \
  99.     -fg blue  
  100.  
  101. $graph tag create bitmap { 7 0  } -bitmap @bitmaps/sharky.bm -anchor sw -bg {}
  102.  
  103. pack append . \
  104.     .header { padx 20 pady 10 }  \
  105.     .graph {} \
  106.     .footer { padx 20 pady 10 }
  107.     
  108. wm min . 0 0
  109. bind $graph <B1-ButtonRelease> { %W crosshairs toggle }
  110.     
  111. proc TurnOnHairs { graph } {
  112.     bind $graph <Any-Motion> {%W crosshairs configure -position @%x,%y}
  113. }
  114. proc TurnOffHairs { graph } {
  115.     bind $graph <Any-Motion> {%W crosshairs configure -position @%x,%y}
  116. }
  117.  
  118. bind $graph <Enter> { TurnOnHairs %W }
  119. bind $graph <Leave> { TurnOffHairs %W }
  120.  
  121. proc FormatLabel { w value } {
  122.     # Determine the element name from the value
  123.     set displaylist [$w element show]
  124.     set index [expr round($value)-1]
  125.     set name [lindex $displaylist $index]
  126.     if { $name == "" } { 
  127.     return $name
  128.     }
  129.     # Return the element label
  130.     set info [$w element configure $name -label]
  131.     return [lindex $info 4]
  132. }
  133.